package com.alibaba.algo.controller.user;

import com.alibaba.algo.annotation.OperateLogAnnotation;
import com.alibaba.algo.apiimpl.user.SysRoleResourceActionServiceImpl;
import com.alibaba.algo.cooperation.common.BaseResult;
import com.alibaba.algo.cooperation.usercomponent.vo.req.user.SelectResourceActionListByRoleReqVO;
import com.alibaba.algo.cooperation.usercomponent.vo.req.user.SelectResourceListByRoleReqVO;
import com.alibaba.algo.cooperation.usercomponent.vo.req.user.UpdateRoleResourceActionVO;
import com.alibaba.algo.cooperation.usercomponent.vo.res.user.ResourceActionInfo;
import com.alibaba.algo.enums.OperateTypeEnum;
import com.alibaba.algo.enums.ResourceTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

/**
 * 类SysResourceController.java的实现描述：资源 Controller
 *
 * @author nieganggang 2021-03-12 16:08:17
 */
@RestController
@RequestMapping(value = "/usercenter-admin-app/admin/sysRoleResourceAction")
public class SysRoleResourceActionController {

    @Autowired
    private SysRoleResourceActionServiceImpl sysRoleResourceActionService;


    @PostMapping("/updateResourceActionListByRole")
    @OperateLogAnnotation(resouceType = ResourceTypeEnum.RESOURCE,operateType = OperateTypeEnum.UPDATE)
    public BaseResult updateResourceActionListByRole(@RequestParam(value = "roleCode")String roleCode,
                                                     @RequestParam(value = "appCode") String appCode,
                                                     @RequestParam(value = "resourceIds") String resourceIds,
                                                     @RequestBody HashMap<Long, ResourceActionInfo> newResourceActionMap){
        return sysRoleResourceActionService.updateResourceActionListByRole(roleCode,appCode,resourceIds,newResourceActionMap);
    }


    @PostMapping("/selectResourceActionTree")
    public BaseResult selectResourceActionTree(@RequestParam(value="appCode") String appCode) {
        return sysRoleResourceActionService.selectResourceActionTree(appCode);
    }

    @PostMapping("/selectResourceActionListByRole")
    public BaseResult selectResourceActionListByRoleReq(@RequestBody SelectResourceActionListByRoleReqVO vo) {
        return sysRoleResourceActionService.selectResourceActionListByRole(vo);
    }

    @PostMapping("/selectResourceListByRole")
    public BaseResult selectResourceListByRole(@RequestBody SelectResourceListByRoleReqVO vo) {
        return sysRoleResourceActionService.selectResourceListByRole(vo);
    }

    @Deprecated
    @PostMapping("/insert")
    @OperateLogAnnotation(resouceType = ResourceTypeEnum.USER,operateType = OperateTypeEnum.INSERT)
    public BaseResult insert(@RequestBody UpdateRoleResourceActionVO vo){
        return sysRoleResourceActionService.insert(vo);
    }

    @Deprecated
    @PostMapping("/delete")
    @OperateLogAnnotation(resouceType = ResourceTypeEnum.USER,operateType = OperateTypeEnum.DELETE)
    public BaseResult delete(@RequestBody UpdateRoleResourceActionVO vo){
        return sysRoleResourceActionService.delete(vo);
    }

}
